﻿using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Media;

namespace TCP232.Views.UserControls;

public partial class GroupBox : UserControl
{
    public GroupBox()
    {
        InitializeComponent();
    }

    private void InitializeComponent()
    {
        AvaloniaXamlLoader.Load(this);
    }

    //private string _text;

    ///// <summary>Gets or sets the text.</summary>
    //public string Text
    //{
    //    get => _text;
    //    set =>  SetAndRaise(TextProperty, ref _text, value);
    //}

    //public string Text
    //{
    //    get { return GetValue(TextProperty)?.ToString(); }
    //    set
    //    {
    //        Debug.WriteLine(">>>" + value);
    //        SetValue(TextProperty, value);
    //    }

    //}

    //public static readonly StyledProperty<string> TextProperty = AvaloniaProperty.Register<GroupBox, string>(nameof(Text));


    //public static readonly DirectProperty<GroupBox, string> TextProperty =
    //    AvaloniaProperty.RegisterDirect<GroupBox, string>(nameof(Text), o => o.Text,
    //        (Action<GroupBox, string>)((o, v) => o.Text = v));

    /// <summary>
    /// Defines the <see cref="Header"/> property.
    /// </summary>
    public static readonly DirectProperty<GroupBox, object> HeaderProperty =
        AvaloniaProperty.RegisterDirect<GroupBox, object>(
            nameof(Header),
            o => o.Header,
            (o, v) => o.Header = /*o.HeaderUpperCase ? v?.ToUpperInvariant() :*/ v);

    /// <summary>
    /// Defines the <see cref="HeaderBackground"/> property.
    /// </summary>
    public static readonly StyledProperty<IBrush> HeaderBackgroundProperty =
        AvaloniaProperty.Register<GroupBox, IBrush>(nameof(HeaderBackground));

    /// <summary>
    /// Defines the <see cref="HeaderForeground"/> property.
    /// </summary>
    public static readonly StyledProperty<IBrush> HeaderForegroundProperty =
        AvaloniaProperty.Register<GroupBox, IBrush>(nameof(HeaderForeground));

    /// <summary>
    /// Defines the <see cref="HeaderMargin"/> property.
    /// </summary>
    public static readonly StyledProperty<Thickness> HeaderMarginProperty =
        AvaloniaProperty.Register<GroupBox, Thickness>(nameof(HeaderMargin));

    /// <summary>
    /// Defines the <see cref="HeaderUpperCase"/> property.
    /// </summary>
    public static readonly StyledProperty<bool> HeaderUpperCaseProperty =
        AvaloniaProperty.Register<GroupBox, bool>(nameof(HeaderUpperCase));

    /// <summary>
    /// Defines the <see cref="BoxShadow"/> property.
    /// </summary>
    public static readonly StyledProperty<BoxShadows> BoxShadowProperty =
        AvaloniaProperty.Register<GroupBox, BoxShadows>(nameof(BoxShadowProperty));

    /// <summary>
    /// Gets or sets a brush with which to paint the Header background.
    /// </summary>
    public IBrush HeaderBackground
    {
        get { return GetValue(HeaderBackgroundProperty); }
        set { SetValue(HeaderBackgroundProperty, value); }
    }

    /// <summary>
    /// Gets or sets a brush with which to paint the Header text.
    /// </summary>
    public IBrush HeaderForeground
    {
        get { return GetValue(HeaderForegroundProperty); }
        set { SetValue(HeaderForegroundProperty, value); }
    }

    /// <summary>
    /// Gets or sets a margin for the header text.
    /// </summary>
    public Thickness HeaderMargin
    {
        get { return GetValue(HeaderMarginProperty); }
        set { SetValue(HeaderMarginProperty, value); }
    }

    /// <summary>
    /// Gets or sets if the header text should be converted to upper-case.
    /// </summary>
    public bool HeaderUpperCase
    {
        get { return GetValue(HeaderUpperCaseProperty); }
        set { SetValue(HeaderUpperCaseProperty, value); }
    }

    private object _header;

    /// <summary>
    /// Gets or sets header text.
    /// </summary>
    public object Header
    {
        get { return _header; }
        set { SetAndRaise(HeaderProperty, ref _header, value); }
    }

    /// <summary>
    /// 阴影。
    /// </summary>
    public BoxShadows BoxShadow
    {
        get { return GetValue(BoxShadowProperty); }
        set { SetValue(BoxShadowProperty, value); }
    }

    ///// <summary>
    ///// 阴影。
    ///// </summary>
    //public CornerRadius CornerRadius
    //{
    //    get
    //    {
    //        return GetValue(CornerRadiusProperty);
    //    }
    //    set
    //    {
    //        SetValue(CornerRadiusProperty, value);
    //    }
    //}
}